<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
 	  xmlns:f="http://java.sun.com/jsf/core"
 	  xmlns:p="http://primefaces.org/ui">  
   
     <body onload="doTimer()">
        <h:form>
	        <div style="float: left; margin-top: 10px;">
	          <p:commandLink action="#{menuBean.goPage('pageInicial')}">
	             <h:graphicImage id="idImgActionEditar" library="images" 
				                 value="#{imageBean.imgLogoTopo}" style="border: none;" />
	          </p:commandLink>
	        </div>
	        
	        <div style="float: right; margin-top: 15px; margin-right: 5px; ">
	        
	            <!-- LOGOFF USUARIO-->
			    <p:menuButton id="idBtnUsuarioLogoff" icon="ui-icon-locked" value="#{sessionBean.usuarioLogado.nome}" > 
			       <p:menuitem value="Alterar Senha" icon="ui-icon-locked"  action="#{usuarioBean.alterarSenha}" />  
			       <p:menuitem value="Fazer Logoff" icon="ui-icon-arrowreturnthick-1-w"  actionListener="#{usuarioBean.logoff}" />  
			    </p:menuButton>
			
		</div>
		<div style="clear: both;"/>
		<div style="float: right; margin-right: 5px;">
				<div id="cronometro_div" style="font-weight: bold; color: black;">Sua sessão expirará em: <span id="cronometro"></span></div>
				<p:remoteCommand name="keepAlive"
					actionListener="#{sessionBean.expirarSessao()}" />
			</div>
	        
	    </h:form>
		
		
		
		<script type="text/javascript">
	//<![CDATA[
       var timer_is_on = timer_is_on= null ? 0 : timer_is_on ;
       var TIME = "#{session.maxInactiveInterval}"; // in seconds
	   var minutos=TIME/60;
       var seconds=00;
       var campo = document.getElementById("cronometro");
       var campo_div = document.getElementById("cronometro_div");
       var processTimer;

    
       
      function doTimer() {
    	 
        if (!timer_is_on) {
            timer_is_on = 1;
            startCountdown();
        }
      }
      
      function stopCount() {
        clearTimeout(processTimer);
        timer_is_on = 0;
        keepAlive();
      }

      function startCountdown()
      {
      	if (seconds<=0){  
      		seconds=60;
      		minutos-=1;
      	 } 
      	 if (minutos<=-1){ 
      		seconds=0;
      		seconds+=1;
      		campo.innerHTML="";
      		campo_div.innerHTML="Sessão expirada!";
      		stopCount();
      		return;
      	 } else{ 
      		seconds-=1
      		if(seconds < 10) {
      			seconds = "0" + seconds;
      		} 
      		campo.innerHTML = " " + minutos+" min "+seconds;
      		
      		processTimer = setTimeout("startCountdown()",1000);

      		 
      	}  
      }		 
     
     
    	//]]>
      </script>
	 </body>    

</html>